//
//  WSEveryNoneView.m
//  WSFramework
//
//  Created by zhangcong on 2018/4/18.
//  Copyright © 2018年 zhangcong. All rights reserved.
//

#import "WSEveryNoneView.h"
#import <WSConst.h>

@implementation WSEveryNoneView

- (void)awakeFromNib {
    [super awakeFromNib];
    
}

+ (instancetype)everyNoneViewWithImage:(NSString *)imageName tipStr:(NSString *)tipStr actionStr:(NSString*)actionStr myDelegate:(id)myDelegate {
//    WSEveryNoneView * noneView  = [[currentBundle loadNibNamed:@"WSEveryNoneView" owner:nil options:nil]lastObject];
    WSEveryNoneView * noneView = [WSEveryNoneView loadFromNib];
    noneView.userInteractionEnabled = actionStr.length>0;
    UIImage * image = WSImage(imageName);
    noneView.queshengIcon.image = image;
    noneView.delegate = myDelegate;
    noneView.titleLabel.text = tipStr;
    
    //    noneView.topY.constant = (kScreenHeight - kNavHeight)/2 - 85;
    CGSize size = CGSizeMake(WScreenWidth - 110, MAXFLOAT);
    size = [tipStr boundingRectWithSize:size options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:noneView.titleLabel.font} context:nil].size;
    noneView.frame = CGRectMake(0, 0, WScreenWidth, size.height + 170 + 20 + 70 + 20);
    
    [noneView.btn setTitle:actionStr forState:UIControlStateNormal];
    actionStr.length == 0 ? (noneView.btn.hidden = YES) : (noneView.btn.hidden = NO);
    return  noneView;
    
}

+ (instancetype)everyNoneViewWithImage:(NSString *)imageName tipStr:(NSString *)tipStr myDelegate:(id)myDelegate {
//    WSEveryNoneView * noneView  = [[currentBundle loadNibNamed:@"WSEveryNoneView" owner:nil options:nil]lastObject];
    WSEveryNoneView * noneView = [WSEveryNoneView loadFromNib];
    noneView.userInteractionEnabled = NO;
    UIImage * image = WSImage(imageName);
    noneView.queshengIcon.image = image;
    noneView.delegate = myDelegate;
    noneView.titleLabel.text = tipStr;
    //    noneView.topY.constant = (kScreenHeight - kNavHeight)/2 - 85;
    CGSize size = CGSizeMake(WScreenWidth - 110, MAXFLOAT);
    size = [tipStr boundingRectWithSize:size options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:noneView.titleLabel.font} context:nil].size;
    noneView.frame = CGRectMake(0, 0, WScreenWidth, size.height + 170 + 20 + 70 + 20);
    [noneView.btn setHidden:YES];
    return  noneView;
    
}

+ (instancetype)everyNoneViewWith:(NSString *)string btnStr:(NSString*)btnStr myDelegate:(id)myDelegate
{
//    WSEveryNoneView * noneView  = [[currentBundle loadNibNamed:@"WSEveryNoneView" owner:nil options:nil]lastObject];
    WSEveryNoneView * noneView = [WSEveryNoneView loadFromNib];
    noneView.userInteractionEnabled = btnStr.length > 0;
    noneView.delegate = myDelegate;
    noneView.titleLabel.text = string;
    //    noneView.topY.constant = (kScreenHeight - kNavHeight)/2 - 100;
    CGSize size = CGSizeMake(WScreenWidth - 110, MAXFLOAT);
    size = [string boundingRectWithSize:size options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:noneView.titleLabel.font} context:nil].size;
    noneView.frame = CGRectMake(0, 0, WScreenWidth, size.height + 170 + 20 + 70 + 20);
    
    [noneView.btn setTitle:btnStr forState:UIControlStateNormal];
    btnStr.length == 0 ? (noneView.btn.hidden = YES) : (noneView.btn.hidden = NO);
    return  noneView;
}

+ (instancetype)everyNoneViewWith:(NSString *)string myDelegate:(id)myDelegate
{
    //    WSEveryNoneView * noneView  = [[currentBundle loadNibNamed:@"WSEveryNoneView" owner:nil options:nil]lastObject];
    WSEveryNoneView * noneView = [WSEveryNoneView loadFromNib];
    noneView.delegate = myDelegate;
    noneView.titleLabel.text = string;
    noneView.queshengIcon.hidden = YES;

    //    noneView.topY.constant = (kScreenHeight - kNavHeight)/2 - 100;
    CGSize size = CGSizeMake(WScreenWidth - 110, MAXFLOAT);
    size = [string boundingRectWithSize:size options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:noneView.titleLabel.font} context:nil].size;
    noneView.frame = CGRectMake(0, 0, WScreenWidth, size.height + 20 + 20);

    
    noneView.top = 20;
    noneView.btn.hidden = YES;
    return  noneView;
}

- (IBAction)didActionBtn:(id)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(view:didAction:data:)]) {
        [self.delegate view:self didAction:kAction_EveryNoneBtn data:nil];
    }
}


@end
